﻿#include "LiBatteryManagerSys.h"

LiBatteryManagerSys::LiBatteryManagerSys(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::LiBatteryManagerSysClass())
{
    ui->setupUi(this);
	init();
	connect(&m_timer, &QTimer::timeout, this, &LiBatteryManagerSys::showBatteryInfo);
	connect(m_communicator, &Communicator::sendInitProtectParamInfo, this, &LiBatteryManagerSys::showProtectParamInfo);
	connect(m_communicator, &Communicator::sendInitFactoryParamInfo, this, &LiBatteryManagerSys::showInitFactoryParamInfo);
	/*connect(this, &LiBatteryManagerSys::sendSerialPort, m_communicator, &Communicator::setSerialPort);*/
	//connect(this, &LiBatteryManagerSys::sendSerialPort, [this](SerialPortInfo info) {
	//	m_communicator->setSerialPort(info);
	//	});
	connect(m_communicateThread, &QThread::started, m_communicator, &Communicator::setSerialPort);
	connect(m_communicator, &Communicator::connectSuccess, this, &LiBatteryManagerSys::connectSuccess);;
}

LiBatteryManagerSys::~LiBatteryManagerSys()
{
    delete ui;
}

quint16 LiBatteryManagerSys::calculateCRC16(const QByteArray &data)
{
	quint16 crc = 0xFFFF;
	QDataStream stream(data);
	while (!stream.atEnd()) {
		quint8 byte;
		stream >> byte;
		crc ^= (quint16)byte;
		for (int i = 0; i < 8; ++i) {
			if (crc & 0x0001) {
				crc >>= 1;
				crc ^= 0xA001;
			}
			else {
				crc >>= 1;
			}
		}
	}
	return crc;
}

void LiBatteryManagerSys::on_pushButton_connect_clicked()
{
	
	SerialPortInfo serialPortInfo;
	serialPortInfo.portname = ui->lineEdit_port->text();
	switch (ui->comboBox_baudrate->currentIndex())
	{
	case 0:
		serialPortInfo.baudRate = QSerialPort::Baud115200;
		break;
	case 1:
		serialPortInfo.baudRate = QSerialPort::Baud38400;
		break;
	case 2:
		serialPortInfo.baudRate = QSerialPort::Baud9600;
		break;
	}

	CoreData &coreData = CoreData::getInstance();
	coreData.m_serialPortInfo = serialPortInfo;

	m_communicator->moveToThread(m_communicateThread);
	m_communicateThread->start();
	//emit sendSerialPort(serialPortInfo);
	//m_communicator->setSerialPort(serialPortInfo);
}


void LiBatteryManagerSys::on_pushButton_CHG_CMD_Close_clicked()
{
	m_communicator->sendCHG_CMD_CloseByteArray();
}

void LiBatteryManagerSys::on_pushButton_CHG_CMD_Open_clicked()
{
	m_communicator->sendCHG_CMD_OpenByteArray();
}

void LiBatteryManagerSys::on_pushButton_DSG_CMD_Close_clicked()
{
	m_communicator->sendDSG_CMD_CloseByteArray();
}

void LiBatteryManagerSys::on_pushButton_DSG_CMD_Open_clicked()
{
	m_communicator->sendDSG_CMD_OpenByteArray();
}

void LiBatteryManagerSys::on_pushButton_RESET_CMD_clicked()
{
	m_communicator->sendRESET_CMDByteArray();
}

void LiBatteryManagerSys::on_pushButton_ERASEFLASH_CMD_clicked()
{
	m_communicator->sendERASEFLASH_CMDByteArray();
}

void LiBatteryManagerSys::on_pushButton_downsend_clicked()
{
	//if (!checkIdentification())
	//{
	//	return;
	//}
	if (!m_isManager)
	{
		m_verifyDialog->exec();
	}
	if (!m_isManager)
	{
		return;
	}

	downsendDataWithPos();

	//QByteArray sumByteArray;
	//sumByteArray.append(static_cast<char>(0x01));
	//sumByteArray.append(static_cast<char>(0x06));
	//QString addressStr = ui->lineEdit_address->text();
	//QString valueStr = ui->lineEdit_value->text();
	//QByteArray addressByte,valueByte;
	//for (int i = 0; i < addressStr.size(); i += 2) {
	//	QString byteStr = addressStr.mid(i, 2); // 从字符串中获取两个字符
	//	bool ok;
	//	uchar byteValue = byteStr.toUShort(&ok, 16); // 将两个字符解析为十六进制数值
	//	if (ok) {
	//		addressByte.append(byteValue); // 将字节添加到 QByteArray 中
	//	}
	//	else {
	//		qDebug() << "Invalid hex string";
	//		break;
	//	}
	//}
	//sumByteArray.append(addressByte);
	//for (int j = 0; j < valueStr.size(); j += 2) {
	//	QString byteStr = valueStr.mid(j, 2); // 从字符串中获取两个字符
	//	bool ok;
	//	uchar byteValue = byteStr.toUShort(&ok, 16); // 将两个字符解析为十六进制数值
	//	if (ok) {
	//		valueByte.append(byteValue); // 将字节添加到 QByteArray 中
	//	}
	//	else {
	//		qDebug() << "Invalid hex string";
	//		break;
	//	}
	//}
	//sumByteArray.append(valueByte);
	//quint16 crc16 = calculateCRC16(sumByteArray);
	//sumByteArray.append(static_cast<char>(crc16 & 0xFF));
	//sumByteArray.append(static_cast<char>((crc16 >> 8) & 0xFF));
	//m_communicator->writeData(sumByteArray);
}

void LiBatteryManagerSys::on_toolButton_select_clicked()
{
	QString filePath = QFileDialog::getOpenFileName(this, u8"请选择配置文件", "");
	ui->lineEdit_config->setText(filePath);
}

void LiBatteryManagerSys::on_pushButton_confirmKey()
{
	m_updateTimer.start(1000);
	connect(&m_updateTimer, &QTimer::timeout, [this]() {
		ui->label_158->setText(QString::number(m_updateTime++) + "S");
		});
	m_mutex.lock();
	m_communicator->updateBMS(ui->lineEdit_config->text());
	m_mutex.unlock();
}

void LiBatteryManagerSys::on_pushButton_more_clicked()
{
	m_moreInfoDialog->exec();
}

void LiBatteryManagerSys::on_pushButton_shiftLanguage_clicked()
{
	if (m_isChinese)
	{
		setEnglish();
		m_isChinese = false;
	}
	else {
		setChinese();
		m_isChinese = true;
	}
	emit sendLanguageType(m_isChinese);
}

void LiBatteryManagerSys::showBatteryInfo()
{
	ui->lineEdit_Voltage->setText(QString::number(CoreData::m_batteryInfo.voltage/10));
	ui->lineEdit_CurCadc->setText(QString::number(CoreData::m_batteryInfo.curCade/10 - 3000));
	ui->lineEdit_PACK_RWH->setText(QString::number(CoreData::m_batteryInfo.pack_RWH));
	ui->lineEdit_Vsum->setText(QString::number(CoreData::m_batteryInfo.vSum));
	ui->lineEdit_CycleCount->setText(QString::number(CoreData::m_batteryInfo.cycleCount));
	ui->lineEdit_Vmax->setText(QString::number(CoreData::m_batteryInfo.vmax));
	ui->lineEdit_Vmin->setText(QString::number(CoreData::m_batteryInfo.vmin));
	ui->lineEdit_VmaxNo->setText(QString::number(CoreData::m_batteryInfo.vmaxNo));
	ui->lineEdit_VminNo->setText(QString::number(CoreData::m_batteryInfo.vminNo));
	ui->lineEdit_Tmax->setText(QString::number(CoreData::m_batteryInfo.tmax/10 - 40));
	ui->lineEdit_Tmin->setText(QString::number(CoreData::m_batteryInfo.tmin/10 - 40));
	ui->lineEdit_Tmaxno->setText(QString::number(CoreData::m_batteryInfo.tmaxNo));
	ui->lineEdit_Tminno->setText(QString::number(CoreData::m_batteryInfo.tminNo));
	for (int i = 0;i<CoreData::m_batteryInfo.protectInfoVec.size();i++)
	{
		ui->plainTextEdit_protect->appendPlainText(CoreData::m_batteryInfo.protectInfoVec[i]);
	}
	
	showBatteryDetailInfo();
}

void LiBatteryManagerSys::showBatteryDetailInfo()
{
	for (int i = 0;i<300;i++)
	{
		m_vItemVec[i]->setText(QString::number(CoreData::m_batteryDetailInfo.allVCell[i]));
		m_tItemVec[i]->setText(QString::number(CoreData::m_batteryDetailInfo.allTemp[i]/10 - 40));
	}
}

void LiBatteryManagerSys::showProtectParamInfo(ProtectParamInfo protectParamInfo)
{
	ui->lineEdit_TOV->setText(QString::number(protectParamInfo.tov.protectValue*0.1));
	ui->lineEdit_TOVDelay->setText(QString::number(protectParamInfo.tov.protectDelay*0.1));
	ui->lineEdit_TOVR->setText(QString::number(protectParamInfo.tov.releaseValue*0.1));
	ui->lineEdit_TOVRDelay->setText(QString::number(protectParamInfo.tov.releaseDelay*0.1));

	ui->lineEdit_OV->setText(QString::number(protectParamInfo.ov.protectValue));
	ui->lineEdit_OVDelay->setText(QString::number(protectParamInfo.ov.protectDelay*0.1));
	ui->lineEdit_OVR->setText(QString::number(protectParamInfo.ov.releaseValue));
	ui->lineEdit_OVRDelay->setText(QString::number(protectParamInfo.ov.releaseDelay*0.1));

	ui->lineEdit_TUV->setText(QString::number(protectParamInfo.tuv.protectValue*0.1));
	ui->lineEdit_TUVDelay->setText(QString::number(protectParamInfo.tuv.protectDelay*0.1));
	ui->lineEdit_TUVR->setText(QString::number(protectParamInfo.tuv.releaseValue*0.1));
	ui->lineEdit_TUVRDelay->setText(QString::number(protectParamInfo.tuv.releaseDelay*0.1));

	ui->lineEdit_UV->setText(QString::number(protectParamInfo.uv.protectValue));
	ui->lineEdit_UVDelay->setText(QString::number(protectParamInfo.uv.protectDelay*0.1));
	ui->lineEdit_UVR->setText(QString::number(protectParamInfo.uv.releaseValue));
	ui->lineEdit_UVRDelay->setText(QString::number(protectParamInfo.uv.releaseDelay*0.1));

	ui->lineEdit_OTD->setText(QString::number(protectParamInfo.otd.protectValue*0.1 - 40));
	ui->lineEdit_OTDDelay->setText(QString::number(protectParamInfo.otd.protectDelay*0.1));
	ui->lineEdit_OTDR->setText(QString::number(protectParamInfo.otd.releaseValue*0.1 - 40));
	ui->lineEdit_OTDRDelay->setText(QString::number(protectParamInfo.otd.releaseDelay*0.1));

	ui->lineEdit_OTC->setText(QString::number(protectParamInfo.otc.protectValue*0.1 - 40));
	ui->lineEdit_OTCDelay->setText(QString::number(protectParamInfo.otc.protectDelay*0.1));
	ui->lineEdit_OTCR->setText(QString::number(protectParamInfo.otc.releaseValue*0.1 - 40));
	ui->lineEdit_OTCRDelay->setText(QString::number(protectParamInfo.otc.releaseDelay*0.1));

	ui->lineEdit_UTD->setText(QString::number(protectParamInfo.utd.protectValue*0.1 - 40));
	ui->lineEdit_UTDDelay->setText(QString::number(protectParamInfo.utd.protectDelay*0.1));
	ui->lineEdit_UTDR->setText(QString::number(protectParamInfo.utd.releaseValue*0.1 - 40));
	ui->lineEdit_UTDRDelay->setText(QString::number(protectParamInfo.utd.releaseDelay*0.1));

	ui->lineEdit_UTC->setText(QString::number(protectParamInfo.utc.protectValue*0.1 - 40));
	ui->lineEdit_UTCDelay->setText(QString::number(protectParamInfo.utc.protectDelay*0.1));
	ui->lineEdit_UTCR->setText(QString::number(protectParamInfo.utc.releaseValue*0.1 - 40));
	ui->lineEdit_UTCRDelay->setText(QString::number(protectParamInfo.utc.releaseDelay*0.1));

	ui->lineEdit_OCD->setText(QString::number(protectParamInfo.ocd1.protectValue*0.1));
	ui->lineEdit_OCDDelay->setText(QString::number(protectParamInfo.ocd1.protectDelay*0.1));
	ui->lineEdit_OCDR->setText(QString::number(protectParamInfo.ocd1.releaseValue*0.1));
	ui->lineEdit_OCDRDelay->setText(QString::number(protectParamInfo.ocd1.releaseDelay*0.1));

	ui->lineEdit_OCC->setText(QString::number(protectParamInfo.occ.protectValue*0.1));
	ui->lineEdit_OCCDelay->setText(QString::number(protectParamInfo.occ.protectDelay*0.1));
	ui->lineEdit_OCCR->setText(QString::number(protectParamInfo.occ.releaseValue*0.1));
	ui->lineEdit_OCCRDelay->setText(QString::number(protectParamInfo.occ.releaseDelay*0.1));

	ui->lineEdit_OCD2->setText(QString::number(protectParamInfo.ocd2.protectValue*0.1));
	ui->lineEdit_OCD2Delay->setText(QString::number(protectParamInfo.ocd2.protectDelay*0.1));
	ui->lineEdit_OCD2R->setText(QString::number(protectParamInfo.ocd2.releaseValue*0.1));
	ui->lineEdit_OCD2RDelay->setText(QString::number(protectParamInfo.ocd2.releaseDelay*0.1));

	ui->lineEdit_OTMOS->setText(QString::number(protectParamInfo.otMos.protectValue*0.1 - 40));
	ui->lineEdit_OTMOSDelay->setText(QString::number(protectParamInfo.otMos.protectDelay*0.1));
	ui->lineEdit_OTMOSR->setText(QString::number(protectParamInfo.otMos.releaseValue*0.1 - 40));
	ui->lineEdit_OTMOSRDelay->setText(QString::number(protectParamInfo.otMos.releaseDelay*0.1));

	ui->lineEdit_SC->setText(QString::number(protectParamInfo.sc));
}

void LiBatteryManagerSys::showInitFactoryParamInfo(FactoryParamInfo factoryParamInfo)
{
	ui->lineEdit_UART1_ADDR->setText(QString::number(factoryParamInfo.UART1_ADDR));
	ui->lineEdit_UART1_Bound->setText(QString::number(factoryParamInfo.UART1_Bound*100));
	ui->lineEdit_UART2_ADDR->setText(QString::number(factoryParamInfo.UART2_ADDR));
	ui->lineEdit_UART2_Bound->setText(QString::number(factoryParamInfo.UART2_Bound * 100));
	ui->lineEdit_UART3_ADDR->setText(QString::number(factoryParamInfo.UART3_ADDR));
	ui->lineEdit_UART3_Bound->setText(QString::number(factoryParamInfo.UART3_Bound * 100));
	ui->lineEdit_UART4_ADDR->setText(QString::number(factoryParamInfo.UART4_ADDR));
	ui->lineEdit_UART4_Bound->setText(QString::number(factoryParamInfo.UART4_Bound * 100));
	ui->lineEdit_CAN1_BPS->setText(QString::number(factoryParamInfo.CAN1_BPS));
	ui->lineEdit_CAN2_BPS->setText(QString::number(factoryParamInfo.CAN2_BPS));
	ui->lineEdit_CAN3_BPS->setText(QString::number(factoryParamInfo.CAN3_BPS));
	ui->lineEdit_CAN4_BPS->setText(QString::number(factoryParamInfo.CAN4_BPS));
	ui->lineEdit_PACK_IterationFcc->setText(QString::number(factoryParamInfo.PACK_IterationFcc*0.1));
	ui->lineEdit_CHG_Voltage->setText(QString::number(factoryParamInfo.CHG_Voltage*0.1));
	ui->lineEdit_CHG_Current->setText(QString::number(factoryParamInfo.CHG_Current*0.1));
	ui->lineEdit_REALRC_H->setText(QString::number(factoryParamInfo.REALRC_H));
	ui->lineEdit_REALRC_L->setText(QString::number(factoryParamInfo.REALRC_L));
	ui->lineEdit_OFFECT_I->setText(QString::number(factoryParamInfo.OFFECT_I*0.1));
	ui->lineEdit_SampRes->setText(QString::number(factoryParamInfo.SampRes));
	ui->lineEdit_HOT_MODE->setText(QString::number(factoryParamInfo.HOT_MODE));
	ui->lineEdit_HOT_ON_TEMP->setText(QString::number(factoryParamInfo.HOT_ON_TEMP*0.1-40));
	ui->lineEdit_HOT_OFF_TEMP->setText(QString::number(factoryParamInfo.HOT_OFF_TEMP*0.1 - 40));
	ui->lineEdit_CHG_DSG_MODE->setText(QString::number(factoryParamInfo.CHG_DSG_MODE));
	ui->lineEdit_KEY_MODE->setText(QString::number(factoryParamInfo.KEY_MODE));
	ui->lineEdit_CD_ForceTime->setText(QString::number(factoryParamInfo.CD_ForceTime*0.1));
	switch (factoryParamInfo.Battery_Type)
	{
	case 0:
		ui->lineEdit_Battery_Type->setText(u8"铁锂");
		break;
	case 1:
		ui->lineEdit_Battery_Type->setText(u8"铁锂");
		break;
	case 2:
		ui->lineEdit_Battery_Type->setText(u8"铁锂");
		break;
	default:
		ui->lineEdit_Bal_Type->setText("NOT FOUND");
		break;
	}
	ui->lineEdit_Bal_Res->setText(QString::number(factoryParamInfo.Bal_Res));
	switch (factoryParamInfo.Bal_Type)
	{
	case 0:
		ui->lineEdit_Bal_Type->setText(u8"充电均衡");
		break;
	case 1:
		ui->lineEdit_Bal_Type->setText(u8"放电均衡");
		break;
	default:
		ui->lineEdit_Bal_Type->setText("NOT FOUND");
		break;
	}
	ui->lineEdit_Bal_ONVol->setText(QString::number(factoryParamInfo.Bal_ONVol));
	ui->lineEdit_Bal_Vdiff->setText(QString::number(factoryParamInfo.Bal_Vdiff));
	switch (factoryParamInfo.LowPower_BEEP_EN)
	{
	case 0:
		ui->lineEdit_LowPower_BEEP_EN->setText(u8"失能");
		break;
	case 1:
		ui->lineEdit_LowPower_BEEP_EN->setText(u8"使能");
		break;
	default:
		ui->lineEdit_LowPower_BEEP_EN->setText("NOT FOUND");
		break;
	}
	ui->lineEdit_AFECELLNUMTABLE1->setText(QString::number(factoryParamInfo.AFE[0]));
	ui->lineEdit_AFECELLNUMTABLE2->setText(QString::number(factoryParamInfo.AFE[1]));
	ui->lineEdit_AFECELLNUMTABLE3->setText(QString::number(factoryParamInfo.AFE[2]));
}

void LiBatteryManagerSys::protectParamChanged()
{
	QLineEdit *lineEdit = qobject_cast<QLineEdit*>(sender());
	if (!lineEdit)
		return;

	float newData = lineEdit->text().toFloat();
	int writeInt = newData * 10;
	int writeInt1 = lineEdit->text().toInt();
	int writeInt2 = (newData + 40) * 10;
	if (lineEdit == ui->lineEdit_TOV)
	{
		m_communicator->writeTOV(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_TOVDelay)
	{
		m_communicator->writeTOVDelay(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_TOVR)
	{
		m_communicator->writeTOVR(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_TOVRDelay)
	{
		m_communicator->writeTOVRDelay(writeInt);
		return;
	}

	if (lineEdit == ui->lineEdit_OV)
	{
		m_communicator->writeOV(writeInt1);
		return;
	}
	if (lineEdit == ui->lineEdit_OVDelay)
	{
		m_communicator->writeOVDelay(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_OVR)
	{
		m_communicator->writeOVR(writeInt1);
		return;
	}
	if (lineEdit == ui->lineEdit_OVRDelay)
	{
		m_communicator->writeOVRDelay(writeInt);
		return;
	}

	if (lineEdit == ui->lineEdit_TUV)
	{
		m_communicator->writeTUV(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_TUVDelay)
	{
		m_communicator->writeTUVDelay(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_TUVR)
	{
		m_communicator->writeTUVR(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_TUVRDelay)
	{
		m_communicator->writeTUVRDelay(writeInt);
		return;
	}

	if (lineEdit == ui->lineEdit_UV)
	{
		m_communicator->writeUV(writeInt1);
		return;
	}
	if (lineEdit == ui->lineEdit_UVDelay)
	{
		m_communicator->writeUVDelay(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_UVR)
	{
		m_communicator->writeUVR(writeInt1);
		return;
	}
	if (lineEdit == ui->lineEdit_UVRDelay)
	{
		m_communicator->writeUVRDelay(writeInt);
		return;
	}

	if (lineEdit == ui->lineEdit_OTD)
	{
		m_communicator->writeOTD(writeInt2);
		return;
	}
	if (lineEdit == ui->lineEdit_OTDDelay)
	{
		m_communicator->writeOTDDelay(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_OTDR)
	{
		m_communicator->writeOTDR(writeInt2);
		return;
	}
	if (lineEdit == ui->lineEdit_OTDRDelay)
	{
		m_communicator->writeOTDRDelay(writeInt);
		return;
	}

	if (lineEdit == ui->lineEdit_OTC)
	{
		m_communicator->writeOTC(writeInt2);
		return;
	}
	if (lineEdit == ui->lineEdit_OTCDelay)
	{
		m_communicator->writeOTCDelay(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_OTCR)
	{
		m_communicator->writeOTCR(writeInt2);
		return;
	}
	if (lineEdit == ui->lineEdit_OTCRDelay)
	{
		m_communicator->writeOTCRDelay(writeInt);
		return;
	}

	if (lineEdit == ui->lineEdit_UTD)
	{
		m_communicator->writeUTD(writeInt2);
		return;
	}
	if (lineEdit == ui->lineEdit_UTDDelay)
	{
		m_communicator->writeUTDDelay(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_UTDR)
	{
		m_communicator->writeUTDR(writeInt2);
		return;
	}
	if (lineEdit == ui->lineEdit_UTDRDelay)
	{
		m_communicator->writeUTDRDelay(writeInt);
		return;
	}

	if (lineEdit == ui->lineEdit_UTC)
	{
		m_communicator->writeUTC(writeInt2);
		return;
	}
	if (lineEdit == ui->lineEdit_UTCDelay)
	{
		m_communicator->writeUTCDelay(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_UTCR)
	{
		m_communicator->writeUTCR(writeInt2);
		return;
	}
	if (lineEdit == ui->lineEdit_UTCRDelay)
	{
		m_communicator->writeUTCRDelay(writeInt);
		return;
	}

	if (lineEdit == ui->lineEdit_OCD)
	{
		m_communicator->writeOCD1(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_OCDDelay)
	{
		m_communicator->writeOCD1Delay(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_OCDR)
	{
		m_communicator->writeOCD1R(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_OCDRDelay)
	{
		m_communicator->writeOCD1RDelay(writeInt);
		return;
	}

	if (lineEdit == ui->lineEdit_OCC)
	{
		m_communicator->writeOCC(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_OCCDelay)
	{
		m_communicator->writeOCCDelay(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_OCCR)
	{
		m_communicator->writeOCCR(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_OCCRDelay)
	{
		m_communicator->writeOCCRDelay(writeInt);
		return;
	}

	if (lineEdit == ui->lineEdit_OCD2)
	{
		m_communicator->writeOCD2(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_OCD2Delay)
	{
		m_communicator->writeOCD2Delay(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_OCD2R)
	{
		m_communicator->writeOCD2R(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_OCD2RDelay)
	{
		m_communicator->writeOCD2RDelay(writeInt);
		return;
	}

	if (lineEdit == ui->lineEdit_SC)
	{
		m_communicator->writeSC(writeInt1);
		return;
	}

	if (lineEdit == ui->lineEdit_OTMOS)
	{
		m_communicator->writeOTMOS(writeInt2);
		return;
	}
	if (lineEdit == ui->lineEdit_OTMOSDelay)
	{
		m_communicator->writeOTMOSDelay(writeInt);
		return;
	}
	if (lineEdit == ui->lineEdit_OTMOSR)
	{
		m_communicator->writeOTMOSR(writeInt2);
		return;
	}
	if (lineEdit == ui->lineEdit_OTMOSRDelay)
	{
		m_communicator->writeOTMOSRDelay(writeInt);
		return;
	}
}

void LiBatteryManagerSys::factoryParamChanged()
{
	if (!m_isManager)
	{
		m_verifyDialog->exec();
	}
	if (!m_isManager)
	{
		return;
	}

	QLineEdit *lineEdit = qobject_cast<QLineEdit*>(sender());
	if (!lineEdit)
		return;

	float newData = lineEdit->text().toFloat();
	int writeInt = lineEdit->text().toInt();
	int writeInt1 = newData * 10;
	int writeInt2 = newData * 100;
	int writeInt3 = (newData + 40) * 10;
	if (lineEdit == ui->lineEdit_UART1_ADDR)
	{
		m_communicator->writeUART1_ADDR(writeInt2);
		return;
	}
}

// void LiBatteryManagerSys::TOVChanged()
// {
// 	float newData = ui->lineEdit_TOV->text().toFloat();
// 	int writeInt = newData * 10;
// 	m_communicator->writeTOV(writeInt);
// }
// 
// void LiBatteryManagerSys::TOVDelayChanged()
// {
// 	float newData = ui->lineEdit_TOVDelay->text().toFloat();
// 	int writeInt = newData * 10;
// 	m_communicator->writeTOVDelay(writeInt);
// }
// 
// void LiBatteryManagerSys::TOVRChanged()
// {
// 	float newData = ui->lineEdit_TOVR->text().toFloat();
// 	int writeInt = newData * 10;
// 	m_communicator->writeTOVR(writeInt);
// }
// 
// void LiBatteryManagerSys::TOVRDelayChanged()
// {
// 	float newData = ui->lineEdit_TOVRDelay->text().toFloat();
// 	int writeInt = newData * 10;
// 	m_communicator->writeTOVRDelay(writeInt);
// }

void LiBatteryManagerSys::shiftTabWidget(int index)
{
	if (!activeState)
	{
		return;
	}
	if (m_lastIndex == index)
	{
		return;
	}
	if (index != 0)
	{
		m_timer.stop();
	}
	else
	{
		m_timer.start(FLUSH_INTERVAL_TIME);
	}
	m_lastIndex = index;
}

void LiBatteryManagerSys::shiftStationAddress(int index)
{
	QByteArray hexBytes = QByteArray::number(index, 16);
	hexBytes = hexBytes.rightJustified(2, '0');
	m_mutex.lock();
	CoreData::_nowStationAddress = hexBytes;
	m_mutex.unlock();
}

void LiBatteryManagerSys::startTimer()
{
	m_timer.start(FLUSH_INTERVAL_TIME);
}

void LiBatteryManagerSys::connectSuccess()
{
	QMessageBox::warning(this, "Tips", "Connect Success......");
	activeState = true;
}

void LiBatteryManagerSys::downsendDataWithPos()
{
	QByteArray sumByteArray;
	//sumByteArray.append(static_cast<char>(0x01));
	sumByteArray.append(CoreData::_nowStationAddress);
	sumByteArray.append(static_cast<char>(0x06));
	QString addressStr = ui->lineEdit_address->text();
	QString valueStr = ui->lineEdit_value->text();

	//可在communicator里封装
	QByteArray addressByte, valueByte;
	for (int i = 0; i < addressStr.size(); i += 2) {
		QString byteStr = addressStr.mid(i, 2); // 从字符串中获取两个字符
		bool ok;
		uchar byteValue = byteStr.toUShort(&ok, 16); // 将两个字符解析为十六进制数值
		if (ok) {
			addressByte.append(byteValue); // 将字节添加到 QByteArray 中
		}
		else {
			qDebug() << "Invalid hex string";
			break;
		}
	}
	sumByteArray.append(addressByte);
	for (int j = 0; j < valueStr.size(); j += 2) {
		QString byteStr = valueStr.mid(j, 2); // 从字符串中获取两个字符
		bool ok;
		uchar byteValue = byteStr.toUShort(&ok, 16); // 将两个字符解析为十六进制数值
		if (ok) {
			valueByte.append(byteValue); // 将字节添加到 QByteArray 中
		}
		else {
			qDebug() << "Invalid hex string";
			break;
		}
	}
	sumByteArray.append(valueByte);
	quint16 crc16 = calculateCRC16(sumByteArray);
	sumByteArray.append(static_cast<char>(crc16 & 0xFF));
	sumByteArray.append(static_cast<char>((crc16 >> 8) & 0xFF));
	m_communicator->writeData(sumByteArray);
}

void LiBatteryManagerSys::init()
{
	m_communicateThread = new QThread();
	initVerifyDialog();
	initMoreInfoDialog();
	initCommunicator();
	initUIData();
	initProtectParamTabWidget();
	initProtectParamTabWidgetSignalsAndSlots();
	initFactoryParamTabWidgetSiganlSAndSlots();
}

void LiBatteryManagerSys::initVerifyDialog()
{
	m_verifyDialog = new VerifyDialog(this);
	connect(m_verifyDialog, &VerifyDialog::sendCheckResult, [this](bool checkResult) {
		if (!checkResult)
		{
			QMessageBox::warning(this, "Tips", "Password Error!!!");
			return;
		}
		else
		{
			m_isManager = true;
			QMessageBox::warning(this, "Tips", "Password Correct!!!");
			return;
		}
		});
	connect(this, &LiBatteryManagerSys::sendLanguageType, m_verifyDialog, &VerifyDialog::shiftLanguage);
	
}

void LiBatteryManagerSys::initMoreInfoDialog()
{
	m_moreInfoDialog = new MoreInfoDialog(this);
}

void LiBatteryManagerSys::initCommunicator()
{
	m_communicator = new Communicator();
	connect(m_communicator, &Communicator::updateSuccess, [this]() {
		m_updateTimer.stop();
		ui->label_157->setText("100%");
		ui->horizontalSlider->setValue(100);
		QMessageBox::warning(this, "Tips", "Update Finished!!!");
		});
	connect(m_communicator, &Communicator::updateError, [this]() {
		m_updateTimer.stop();
		ui->label_157->setText("0%");
		ui->horizontalSlider->setValue(0);
		QMessageBox::warning(this, "Tips", "Update Failed......");
		});
	connect(m_communicator, &Communicator::updateSchedule, [this](int scheduleData) {
		if (scheduleData>100)
		{
			ui->label_157->setText("100%");
			ui->horizontalSlider->setValue(100);
		}else{
			ui->label_157->setText(QString::number(scheduleData)+"%");
			ui->horizontalSlider->setValue(scheduleData);
		}
		});
}

void LiBatteryManagerSys::initUIData()
{
	ui->lineEdit_port->setText("COM1");

	ui->tableWidget->setRowCount(300);
	ui->tableWidget->verticalHeader()->hide();
	for (int i = 0; i < 300; i++)
	{
		QTableWidgetItem *item = new QTableWidgetItem(QString::number(i + 1));
		ui->tableWidget->setItem(i, 0, item);
		m_numItemVec.append(item);
		for (int j = 1; j < 3; j++) {
			QTableWidgetItem *item2 = new QTableWidgetItem();
			ui->tableWidget->setItem(i, j, item2);
			if (j == 1)
			{
				m_vItemVec.append(item2);
			}
			else
			{
				m_tItemVec.append(item2);
			}
		}
	}
	//ui->tableWidget->item(1, 1)->setText("------------wsh");
	//m_vItemVec[2]->setText("------------wsh");

	for (int k = 0; k<256;k++)
	{
		ui->comboBox_station->addItem(QString::number(k));
	}
	ui->comboBox_station->setCurrentIndex(1);
	CoreData::_nowStationAddress = QByteArray::fromStdString("0x01");
}

void LiBatteryManagerSys::initProtectParamTabWidget()
{

}

void LiBatteryManagerSys::initProtectParamTabWidgetSignalsAndSlots()
{
	connect(ui->lineEdit_TOV, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_TOVDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_TOVR, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_TOVRDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OV, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OVDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OVR, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OVRDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_TUV, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_TUVDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_TUVR, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_TUVRDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_UV, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_UVDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_UVR, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_UVRDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OTD, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OTDDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OTDR, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OTDRDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OTC, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OTCDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OTCR, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OTCRDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_UTD, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_UTDDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_UTDR, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_UTDRDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_UTC, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_UTCDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_UTCR, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_UTCRDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OCD, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OCDDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OCDR, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OCDRDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OCC, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OCCDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OCCR, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OCCRDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OCD2, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OCD2Delay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OCD2R, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OCD2RDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_SC, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OTMOS, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OTMOSDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OTMOSR, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
	connect(ui->lineEdit_OTMOSRDelay, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::protectParamChanged);
}

void LiBatteryManagerSys::initFactoryParamTabWidgetSiganlSAndSlots()
{
	connect(ui->lineEdit_UART1_ADDR, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_UART1_Bound, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_UART2_ADDR, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_UART2_Bound, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_UART3_ADDR, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_UART3_Bound, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_UART4_ADDR, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_UART4_Bound, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_CAN1_BPS, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_CAN2_BPS, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_CAN3_BPS, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_CAN4_BPS, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_PACK_IterationFcc, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_CHG_Voltage, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_CHG_Current, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_REALRC_H, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_REALRC_L, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_OFFECT_I, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_SampRes, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_HOT_MODE, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_HOT_ON_TEMP, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_HOT_OFF_TEMP, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_CHG_DSG_MODE, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_KEY_MODE, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_CD_ForceTime, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_Battery_Type, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_Bal_Res, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_Bal_Type, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_Bal_ONVol, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_Bal_Vdiff, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
	connect(ui->lineEdit_LowPower_BEEP_EN, &QLineEdit::editingFinished, this, &LiBatteryManagerSys::factoryParamChanged);
}

bool LiBatteryManagerSys::checkIdentification()
{
	if (!m_isManager)
	{
		QString inputPassword = QInputDialog::getText(this, u8"请输入密钥：", u8"请输入：");

		if (inputPassword != CoreData::generatePasswordFromMacAddress() || inputPassword.isEmpty())
		{
			QMessageBox::warning(this, "Tips", "PassWord Error!!!");
			return false;
		}
		m_isManager = true;
		return true;
	}
	return true;
}

void LiBatteryManagerSys::setChinese()
{
	ui->label_language->setText(u8"简体中文");
	ui->label_portNum->setText(u8"端口号:");
	ui->label_baundRate->setText(u8"波特率：");
	ui->label_station->setText(u8"站地址：");
	ui->label_totalCapacity->setText(u8"总容量：");
	ui->label_remainingCapacity->setText(u8"剩余容量：");
	ui->label_totalVoltagee->setText(u8"总电压：");
	ui->label_totalCurrent->setText(u8"总电流：");
	ui->label_power->setText(u8"功率：");
	ui->label_pressureDifference->setText(u8"压差：");
	ui->label_averageVoltage->setText(u8"平均电压：");
	ui->label_cycleNum->setText(u8"循环次数：");
	ui->label_highestVoltage->setText(u8"最高电压：");
	ui->label_maxVoltageTagNum->setText(u8"最高电压位号：");
	ui->label_lowestVoltage->setText(u8"最低电压：");
	ui->label_minVoltageTagNum->setText(u8"最低电压位号：");
	ui->label_highestTemp->setText(u8"最高温度：");
	ui->label_maxTempTagNum->setText(u8"最高温度位号：");
	ui->label_lowestTemp->setText(u8"最低温度：");
	ui->label_minTempTagNum->setText(u8"最低温度位号：");
	ui->tabWidget->setTabText(0, u8"状态信息显示");
	ui->tabWidget->setTabText(1, u8"参数设置");
	ui->tabWidget->setTabText(2, u8"BMS控制");
	ui->tabWidget->setTabText(3, u8"固件升级");
	ui->tabWidget->setTabText(4, u8"厂家参数");
	ui->pushButton_connect->setText(u8"连接设备");
	ui->label_protectInformation->setText(u8"保护信息");
	ui->label_warnInformation->setText(u8"告警信息");

	ui->label_voltageParam->setText(u8"电\n压\n参\n数\n");
	ui->label_tempParam->setText(u8"温\n度\n参\n数\n");
	ui->label_currentParam->setText(u8"电\n流\n参\n数\n");
	ui->label_TOV->setText(u8"总体过压:");
	ui->label_TOVDelay->setText(u8"延时:");
	ui->label_TOVR->setText(u8"释放:");
	ui->label_TOVRDelay->setText(u8"延时:");
	ui->label_SOV->setText(u8"单体过压:");
	ui->label_SOVDelay->setText(u8"延时:");
	ui->label_SOVR->setText(u8"释放:");
	ui->label_SOVRDelay->setText(u8"延时:");
	ui->label_TUV->setText(u8"总体欠压:");
	ui->label_TUVDelay->setText(u8"延时:");
	ui->label_TUVR->setText(u8"释放:");
	ui->label_TUVRDelay->setText(u8"延时:");
	ui->label_SUV->setText(u8"单体欠压:");
	ui->label_SUVDelay->setText(u8"延时:");
	ui->label_SUVR->setText(u8"释放:");
	ui->label_SUVRDelay->setText(u8"延时:");
	ui->label_OverTempDischarge->setText(u8"高温放电:");
	ui->label_OTDDelay->setText(u8"延时:");
	ui->label_OTDR->setText(u8"释放:");
	ui->label_OTDRDelay->setText(u8"延时:");
	ui->label_OverTempCharge->setText(u8"高温充电:");
	ui->label_OTCDelay->setText(u8"延时:");
	ui->label_OTCR->setText(u8"释放:");
	ui->label_OTCRDelay->setText(u8"延时:");
	ui->label_underTempDischarge->setText(u8"低温放电:");
	ui->label_UTDDelay->setText(u8"延时:");
	ui->label_UTDR->setText(u8"释放:");
	ui->label_UTDRDelay->setText(u8"延时:");
	ui->label_underTempCharge->setText(u8"低温充电:");
	ui->label_UTCDelay->setText(u8"延时:");
	ui->label_UTCR->setText(u8"释放:");
	ui->label_UTCRDelay->setText(u8"延时:");
	ui->label_OverTempMOS->setText(u8"MOS高温:");
	ui->label_OTMOSDelay->setText(u8"延时:");
	ui->label_OTMOSR->setText(u8"释放:");
	ui->label_OTMOSRDelay->setText(u8"延时:");
	ui->label_overcurrentDischarge1->setText(u8"放电过流一级:");
	ui->label_OCD1Delay->setText(u8"延时:");
	ui->label_OCD1R->setText(u8"释放:");
	ui->label_OCD1RDelay->setText(u8"延时:");
	ui->label_overcurrentChargeProtect->setText(u8"充电过流保护:");
	ui->label_OCCDelay->setText(u8"延时:");
	ui->label_OCCR->setText(u8"释放:");
	ui->label_OCCRDelay->setText(u8"延时:");
	ui->label_overcurrentDischarge2->setText(u8"放电过流二级:");
	ui->label_OCD2Delay->setText(u8"延时:");
	ui->label_OCD2R->setText(u8"释放:");
	ui->label_OCD2RDelay->setText(u8"延时:");
	ui->label_shortCircuitProtect->setText(u8"短路保护:");
	ui->pushButton_adjustProtect->setText(u8"电流校准");

	ui->pushButton_CHG_CMD_Close->setText(u8"关闭充电开关");
	ui->pushButton_CHG_CMD_Open->setText(u8"打开充电开关");
	ui->pushButton_DSG_CMD_Close->setText(u8"关闭放电开关");
	ui->pushButton_DSG_CMD_Open->setText(u8"打开放电开关");
	ui->pushButton_RESET_CMD->setText(u8"复位BMS");
	ui->pushButton_ERASEFLASH_CMD->setText(u8"恢复出厂");
	ui->label_downsend->setText(u8"下发指令");
	ui->label_address->setText(u8"地址(0x):");
	ui->label_value->setText(u8"数值(0x):");
	ui->pushButton_downsend->setText(u8"下发");

	ui->label_UART1Address->setText(u8"UART1站地址:");
	ui->label_UART1Baund->setText(u8"UART1波特率:");
	ui->label_UART2Address->setText(u8"UART2站地址:");
	ui->label_UART2Baund->setText(u8"UART2波特率:");
	ui->label_UART3Address->setText(u8"UART3站地址:");
	ui->label_UART3Baund->setText(u8"UART3波特率:");
	ui->label_UART4Address->setText(u8"UART4站地址:");
	ui->label_UART4Baund->setText(u8"UART4波特率:");
	ui->label_CAN1Baund->setText(u8"CAN1波特率:");
	ui->label_CAN2Baund->setText(u8"CAN2波特率:");
	ui->label_CAN3Baund->setText(u8"CAN3波特率:");
	ui->label_CAN4Baund->setText(u8"CAN4波特率:");
	ui->label_batteryFullChargeCapacity->setText(u8"电池满充容量:");
	ui->label_chargeRequestVoltage->setText(u8"充电请求电压:");
	ui->label_chargeRequestCurrent->setText(u8"充电请求电流:");
	ui->label_upperLimitOfCapacityIteration->setText(u8"容量迭代上限:");
	ui->label_lowerLimitOfCapacityIteration->setText(u8"容量迭代下限:");
	ui->label_sysIdentificationCurrent->setText(u8"系统识别电流:");
	ui->label_currentDetectionResistanceValue->setText(u8"检流电阻阻值:");
	ui->label_heatStrategy->setText(u8"加热策略:");
	ui->label_heatOnTemp->setText(u8"加热开启温度:");
	ui->label_heatOffTemp->setText(u8"加热关闭温度:");
	ui->label_chargeAndDischargeMode->setText(u8"充放电模式:");
	ui->label_keyType->setText(u8"按键类型:");
	ui->label_batteryType->setText(u8"电池类型:");
	ui->label_equalResistanceValue->setText(u8"均衡电阻阻值:");
	ui->label_balanceModeConfig->setText(u8"均衡模式配置:");
	ui->label_equalOpenVoltage->setText(u8"均衡开启电压:");
	ui->label_balanceOpenPressureDiff->setText(u8"均衡开启压差:");
	ui->label_softwareVersion->setText(u8"软件版本号:");
	ui->label_hardwareVersion->setText(u8"硬件版本号:");
	ui->label_CAndDiscFisrtOpenTime->setText(u8"充放电第一次强制打开时间:");
	ui->label_lowerPowerBuzzerWarnEnable->setText(u8"低电量蜂鸣器警告使能:");
	ui->label_stringNumOfFirstAFE->setText(u8"第一个afe采集的串数:");
	ui->label_stringNumOf2ndAFE->setText(u8"第二个afe采集的串数:");
	ui->label_stringNumOf3rdAFE->setText(u8"第三个afe采集的串数:");
	ui->pushButton_more->setText(u8"更多");

}

void LiBatteryManagerSys::setEnglish()
{
	ui->label_language->setText("English");
	ui->label_portNum->setText("PortNo. :");
	ui->label_baundRate->setText("Baund Rate :");
	ui->label_station->setText("Station Address :");
	ui->label_totalCapacity->setText("Total Capacity :");
	ui->label_remainingCapacity->setText("Remaining Capacity :");
	ui->label_totalVoltagee->setText("Total Voltage :");
	ui->label_totalCurrent->setText("Total Current :");
	ui->label_power->setText("Power :");
	ui->label_pressureDifference->setText("Pressure Difference :");
	ui->label_averageVoltage->setText("Average Voltage :");
	ui->label_cycleNum->setText("Cycle Times :");
	ui->label_highestVoltage->setText("Max Voltage :");
	ui->label_maxVoltageTagNum->setText("Max Voltage Tag Num :");
	ui->label_lowestVoltage->setText("Min Voltage :");
	ui->label_minVoltageTagNum->setText("Min Voltage Tag Num :");
	ui->label_highestTemp->setText("Max Temp :");
	ui->label_maxTempTagNum->setText("Max Temp Tag Num :");
	ui->label_lowestTemp->setText("Min Temp :");
	ui->label_minTempTagNum->setText("Min Temp Tag Num :");
	ui->tabWidget->setTabText(0,"State Information");
	ui->tabWidget->setTabText(1, "Params Setting");
	ui->tabWidget->setTabText(2, "BMS Control");
	ui->tabWidget->setTabText(3, "Firmware Update");
	ui->tabWidget->setTabText(4, "Manufacturer Params");
	ui->pushButton_connect->setText("Connect");
	ui->label_protectInformation->setText("Protect Information");
	ui->label_warnInformation->setText("Warning Information");

	ui->label_voltageParam->setText("Voltage\nParam");
	ui->label_tempParam->setText("Temp\nParam");
	ui->label_currentParam->setText("Current\nParam");
	ui->label_TOV->setText("Total Over Voltage:");
	ui->label_TOVDelay->setText("Delay:");
	ui->label_TOVR->setText("Release:");
	ui->label_TOVRDelay->setText("Delay:");
	ui->label_SOV->setText("Single Over Voltage:");
	ui->label_SOVDelay->setText("Delay:");
	ui->label_SOVR->setText("Release:");
	ui->label_SOVRDelay->setText("Delay:");
	ui->label_TUV->setText("Total Under Voltage:");
	ui->label_TUVDelay->setText("Delay:");
	ui->label_TUVR->setText("Release:");
	ui->label_TUVRDelay->setText("Delay:");
	ui->label_SUV->setText("Single Under Voltage:");
	ui->label_SUVDelay->setText("Delay:");
	ui->label_SUVR->setText("Release:");
	ui->label_SUVRDelay->setText("Delay:");
	ui->label_OverTempDischarge->setText("Over Temp Discharge:");
	ui->label_OTDDelay->setText("Delay:");
	ui->label_OTDR->setText("Release:");
	ui->label_OTDRDelay->setText("Delay:");
	ui->label_OverTempCharge->setText("Over Temp Charge:");
	ui->label_OTCDelay->setText("Delay:");
	ui->label_OTCR->setText("Release:");
	ui->label_OTCRDelay->setText("Delay:");
	ui->label_underTempDischarge->setText("Under Temp Discharge:");
	ui->label_UTDDelay->setText("Delay:");
	ui->label_UTDR->setText("Release:");
	ui->label_UTDRDelay->setText("Delay:");
	ui->label_underTempCharge->setText("Under Temp Charge:");
	ui->label_UTCDelay->setText("Delay:");
	ui->label_UTCR->setText("Release:");
	ui->label_UTCRDelay->setText("Delay:");
	ui->label_OverTempMOS->setText("Over Temp MOS:");
	ui->label_OTMOSDelay->setText("Delay:");
	ui->label_OTMOSR->setText("Release:");
	ui->label_OTMOSRDelay->setText("Delay:");
	ui->label_overcurrentDischarge1->setText("Over Current Discharge 1:");
	ui->label_OCD1Delay->setText("Delay:");
	ui->label_OCD1R->setText("Release:");
	ui->label_OCD1RDelay->setText("Delay:");
	ui->label_overcurrentChargeProtect->setText("Over Current Charge Protect:");
	ui->label_OCCDelay->setText("Delay:");
	ui->label_OCCR->setText("Release:");
	ui->label_OCCRDelay->setText("Delay:");
	ui->label_overcurrentDischarge2->setText("Over Current Discharge 2:");
	ui->label_OCD2Delay->setText("Delay:");
	ui->label_OCD2R->setText("Release:");
	ui->label_OCD2RDelay->setText("Delay:");
	ui->label_shortCircuitProtect->setText("Short Circuit Protect:");
	ui->pushButton_adjustProtect->setText("Current Calibration");

	ui->pushButton_CHG_CMD_Close->setText("Turn off the charge switch");
	ui->pushButton_CHG_CMD_Open->setText("Turn on the charge switch");
	ui->pushButton_DSG_CMD_Close->setText("Turn off the discharge switch");
	ui->pushButton_DSG_CMD_Open->setText("Turn on the discharge switch");
	ui->pushButton_RESET_CMD->setText("Reset BMS");
	ui->pushButton_ERASEFLASH_CMD->setText("Restore factory settings");
	ui->label_downsend->setText("Send Instructions");
	ui->label_address->setText("Address(0x):");
	ui->label_value->setText("Value(0x):");
	ui->pushButton_downsend->setText("Send");

	ui->label_UART1Address->setText("UART1 Station Address:");
	ui->label_UART1Baund->setText("UART1 Bound Rate:");
	ui->label_UART2Address->setText("UART2 Station Address:");
	ui->label_UART2Baund->setText("UART2 Bound Rate:");
	ui->label_UART3Address->setText("UART3 Station Address:");
	ui->label_UART3Baund->setText("UART3 Bound Rate:");
	ui->label_UART4Address->setText("UART4 Station Address:");
	ui->label_UART4Baund->setText("UART4 Bound Rate:");
	ui->label_CAN1Baund->setText("CAN1 Bound Rate:");
	ui->label_CAN2Baund->setText("CAN2 Bound Rate:");
	ui->label_CAN3Baund->setText("CAN3 Bound Rate:");
	ui->label_CAN4Baund->setText("CAN4 Bound Rate:");
	ui->label_batteryFullChargeCapacity->setText("Battery Full Charge Capacity:");
	ui->label_chargeRequestVoltage->setText("Charge Request Voltage:");
	ui->label_chargeRequestCurrent->setText("Charge Request Current:");
	ui->label_upperLimitOfCapacityIteration->setText("Upper Limit Of Capacity Iteration:");
	ui->label_lowerLimitOfCapacityIteration->setText("Lower Limit Of Capacity Iteration:");
	ui->label_sysIdentificationCurrent->setText("System Identification Current:");
	ui->label_currentDetectionResistanceValue->setText("Current Detection Resistance Value:");
	ui->label_heatStrategy->setText("Heat Strategy:");
	ui->label_heatOnTemp->setText("Heat On Temp:");
	ui->label_heatOffTemp->setText("Heat Off Temp:");
	ui->label_chargeAndDischargeMode->setText("Charge And Discharge Mode:");
	ui->label_keyType->setText("Key Type:");
	ui->label_batteryType->setText("Battery Type:");
	ui->label_equalResistanceValue->setText("Balance Resistance Value:");
	ui->label_balanceModeConfig->setText("Balance Mode Config:");
	ui->label_equalOpenVoltage->setText("Balance Open Voltage:");
	ui->label_balanceOpenPressureDiff->setText("Balance Open Pressure Diff:");
	ui->label_softwareVersion->setText("Software Version:");
	ui->label_hardwareVersion->setText("Hardware Version:");
	ui->label_CAndDiscFisrtOpenTime->setText("Charge And Discharge First Open:");
	ui->label_lowerPowerBuzzerWarnEnable->setText("Lower Power Buzzer Warning Enable:");
	ui->label_stringNumOfFirstAFE->setText("String Number Of 1st Afe:");
	ui->label_stringNumOf2ndAFE->setText("String Number Of 2nd Afe:");
	ui->label_stringNumOf3rdAFE->setText("String Number Of 3rd Afe:");
	ui->pushButton_more->setText("More");

}
